Skip to content

fix(datasource): restrict maven registries parsed from pom.xml#2713

Closed
TristanInSec wants to merge 1 commit intogoogle:mainfrom
TristanInSec:harden-maven-registry
Closed

fix(datasource): restrict maven registries parsed from pom.xml#2713
TristanInSec wants to merge 1 commit intogoogle:mainfrom
TristanInSec:harden-maven-registry

Conversation

@TristanInSec
Copy link
Copy Markdown

Summary

Tightens how internal/datasource/maven_registry.go handles <repositories> entries pulled from parsed pom.xml files, which are untrusted input when osv-scanner walks a third-party project:

  • URL validationAddRegistry now rejects non-http(s) schemes and hosts that resolve to loopback / private / link-local / unspecified / multicast addresses. The default registry passed to NewMavenRegistryAPIClient is intentionally exempt so internal Artifactory/Nexus mirrors keep working.
  • Credential gating — a new MavenRegistry.TrustedForAuth flag is set only on the default registry. getProject, getVersionMetadata, and getArtifactMetadata route through a new authFor() helper that returns nil for registries added from pom.xml, so settings.xml <server> credentials can no longer be sent to a repository URL declared inside a dependency's manifest.

Testing

  • go test ./internal/datasource/... — passes, including new tests for scheme rejection, private-IP rejection, and the credential-gating paths.
  • go build ./... — clean.

Registries added through MavenRegistryAPIClient.AddRegistry typically
originate from <repositories> blocks inside pom.xml files, which are
attacker-controlled input when scanning third-party projects. Two
tightenings:

- Validate untrusted registry URLs: require http/https, and reject
  hosts that resolve to loopback, private, link-local, unspecified, or
  multicast addresses. The default registry passed to
  NewMavenRegistryAPIClient is exempt so users can still point
  osv-scanner at internal Artifactory/Nexus mirrors.

- Only attach settings.xml <server> credentials to the default
  registry. Registries added later via AddRegistry are marked
  TrustedForAuth=false and receive no auth, so a pom.xml-declared
  repository cannot pull credentials scoped to an unrelated host.

Unit tests cover the scheme/host rejection paths and the
credential-gating behaviour in getProject, getVersionMetadata, and
getArtifactMetadata.
@G-Rath
Copy link
Copy Markdown
Collaborator

G-Rath commented Apr 10, 2026

@TristanInSec thank you for your contribution!

We are migrating all our native registry clients to osv-scalibr - please make your contribution with osv-scalibr instead. There is an issue for this: google/osv-scalibr#1877

@TristanInSec
Copy link
Copy Markdown
Author

Thanks for the heads up — ported the fix to osv-scalibr in google/osv-scalibr#1970 (against #1877). Happy to iterate there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants